home *** CD-ROM | disk | FTP | other *** search
- /* TITLE: avm:rexx/handlefax.avm */
- /* we want results! Otherwise, we wouldn't get anything from RESULT */
- options results
-
- /* Need to make sure that stdtail.avm is also included */
- signal on halt
- signal on novalue
- signal on syntax
- signal on break_c
-
- /* needed for some of the functions we use */
- call addlib("rexxsupport.library", 0, -30, 0)
-
- /* a higher than normal priority since calls are important to us :) */
- call pragma('priority', 1)
-
- /* ensure that commands are directed to the correct server */
- parse arg servername .
- address value servername
-
-
- parse arg servername mailbox .
- if symbol('mailbox') ~= 'VAR' | mailbox = '' then mailbox = 'manual'
- options failat 50
-
- 'turnoffvoicemode'
-
- 'assumemode' 'Unknown'
-
- 'setserial' '19200' '8' 'N' '1' '7Wire'
- action = rc
- select
- when action = 0 then nop
- when action = 14 then nop
- when action = 16 then nop
- otherwise signal arexxerror
- end
-
- isTrapFax:
- faxprogram = upper(getclip('AVMFaxProgram'))
- if faxprogram = 'TRAPFAX' then do
-
- call showDebugger('Starting TrapFax reception.')
- call time('r')
- /*----------------------------------------*/
- address rexx 'setuptfax.avm'
- /*----------------------------------------*/
-
- 'writeline' 'ATA'
-
- address command "trapfax:tfaxdoor getty"
- call showDebugger('TrapFax reception ' || time('e'))
-
- isGPFax:
- end; else if faxprogram = 'GPFAX' then do
-
- call showDebugger('Starting GPFax reception.')
- call time('r')
-
- address rexx_gpfax 'listen'
- address rexx_gpfax 'recfax'
- faxresult = rc
- address rexx_gpfax 'unlisten'
- call showDebugger('GPFax result is' faxresult)
- call showDebugger('GPFax done ' || time('e'))
-
- isEFax:
- end; else if faxprogram = 'EFAX' then do
- /* create a unique filename */
- efaxFileName = makeUniqueFile()
- call time('r')
- address command 'avm:gnu/efax -p' servername '-r' voiceFile(mailbox, efaxFileName)
- efaxLength = time('e')
-
- end
-
- doneRecFax:
- 'delay' 2
- action = rc
- select
- when action = 0 then nop
- when action = 12 then signal stdabort
- when action = 14 then signal stderror
- when action = 16 then signal stderror
- otherwise signal arexxerror
- end
-
- 'writeline' 'AT+FCLASS=0'
-
- 'readline' '2'
- action = rc
- if action = 0 then value = result
- select
- when action = 0 then nop
- when action = 10 then nop
- when action = 12 then signal stdabort
- when action = 14 then signal stderror
- when action = 16 then signal stderror
- otherwise signal arexxerror
- end
-
- 'readline' '2'
- action = rc
- if action = 0 then value = result
- select
- when action = 0 then nop
- when action = 10 then nop
- when action = 12 then signal stdabort
- when action = 14 then signal stderror
- when action = 16 then signal stderror
- otherwise signal arexxerror
- end
-
- createLog:
- handle = makeUniqueFile()
- call initLogEntry()
-
- log.comment = 'Fax attempted.'
- log.type = 'Try_FAX'
- if faxprogram = 'GPFAX' then do
- if faxresult <= 5 then signal gotfaxgpfax
- end; else if faxprogram = 'TRAPFAX' then do
- call open('cfaxlstfl', 'trapfax:trapfax.log', 'r')
- call open('cfaxnrfl', 'trapfax:incoming/trapfax.sequence', 'r')
- cfaxnr = readln('cfaxnrfl')
- cnewfaxnr = right(cfaxnr, 4, '0')
-
- do forever
- cfax = readln('cfaxlstfl')
- cfaxlsnr = right(left(cfax, 6), 4)
- if cfaxlsnr = cfaxnr | eof('cfaxlstfl') then break
- end
- call close('cfaxlstfl'); call close('cfaxnrfl')
- if left(cfax, 1) ~= 'E' then signal gotfaxtrapfax
- end; else if faxprogram = 'EFAX' then do
-
- if exists(voiceFile(mailbox, efaxFileName) || '.001') then signal gotfaxefax
- end
-
- signal finished
-
- gotfaxgpfax:
- address rexx_gpfax 'reportlog' 1
- faxfilename = result
- log.filename = result
-
- address rexx_gpfax 'reportlog' 6
- log.length = result
- address rexx_gpfax 'reportlog' 2
- log.comment = result 'page(s) received.'
-
- address rexx_gpfax 'reportlog' 4
- log.returnnumber = result
- log.type = 'fax'
- signal finished
-
- gotfaxtrapfax:
- faxfilename = 'trapfax:incoming/In-' || cfaxnr || '.FAX'
- log.filename = faxfilename
- myvar = right(left(cfax, 54), 5)
- myvar = (left(myvar, 2)*60) + (right(myvar, 2))
- log.length = myvar
- myvar = right(left(cfax, 47), 2); myvar = strip(myvar, 'L')
- log.comment = myvar 'page(s)'
- myvar = right(left(cfax, 45), 22)
- myvar = strip(myvar, 'T')
- log.returnnumber = myvar; log.type = 'fax'
- signal finished
-
- gotfaxefax:
- log.filename = efaxFileName
- faxfilename = efaxFileName
- log.type = 'fax'
- log.length = efaxLength
- base = voiceFile(mailbox, efaxFileName) || '.'
- do i = 1 to 999
- if ~exists(base || right(i, 3, '0')) then break
- end
- log.comment = i - 1 'page(s).'
-
- log.returnNumber = getclip(upper(servername || '.faxid'))
- signal finished
-
- finished:
- call saveLogEntry(mailbox, handle)
-
- call loadMailbox(mailbox)
- if upper(log.type) = 'FAX' & mailbox.autofaxforwardb = 1 & mailbox.autofaxforwardscript ~= "" then do
- handle = makeUniqueFile()
- call initLogEntry(); log.origmailbox = mailbox
- log.filename = voiceFile(mailbox, faxfilename); log.type = 'fax'
- log.returnsendfunc = mailbox.autofaxforwardscript; log.returninterval = 5
- log.returnretry = 3; log.returnnumber = mailbox.autofaxforward
- call saveLogEntry('Outgoing', handle)
- end
-
- exit
-
- /* TITLE: avm:rexx/simplestdtail.avm */
- /* This is the standard tail */
- exit
-
- exit
-
- mailboxDir: procedure
- parse arg mailbox
-
- return 'avm:' || mailbox || '/'
-
- logFile: procedure
- parse arg mailbox, magiccookie
-
- return 'avm:' || mailbox || '/logs/' || magiccookie
-
- voiceFile: procedure
- parse arg mailbox, magiccookie
-
- if (verify(magiccookie, '/:', 'M') = 0) then
- return 'avm:' || mailbox || '/voices/' || magiccookie
- else
- return magiccookie
-
- makeUniqueFile: procedure
- if arg() ~= 0 then do
- rc = "makeUniqueFile: bad args"
- signal error
- end
- return address() || '.' || date('i') || '.' || time('s') || '.' || random(1, 999, time('s'))
-
- convertToDate: procedure
- if arg() ~= 1 then do
- rc = "convertToDate: bad args"
- signal error
- end
- parse arg timeInC
-
- actualTime = (timeInC - (2922)*86400) // (86400)
- actualDate = (timeInC - actualTime - 2922*86400) % 86400
-
- return actualDate /* returning it in 'internal' format */
-
- convertToTime: procedure
- if arg() ~= 1 then do
- rc = "convertToTime: bad args"
- signal error
- end
- parse arg timeInC
-
- actualTime = (timeInC - (2922)*86400) // (86400)
-
- return actualTime
-
- cTime: procedure
- /* 2922 = 8*365 + 2 */
- /* 86400 = 24*60*60 */
- return (date('i')+2922)*86400 + time('s')
-
- /* this returns a handle that you must use after initializing log. */
- initLogEntry: procedure expose log.
- if arg() ~= 0 then do
- rc = "initLogEntry: bad args"
- signal error
- end
-
- drop log.
- log. = ''
-
- acidname = getclip(address() || 'CIDNAME')
- acidnumber = getclip(address() || 'CIDNUMBER')
-
- /* 2922 = 8*365 + 2 */
- /* 86400 = 24*60*60 */
- log.time = (date('i')+2922)*86400 + time('s')
- log.cidname = acidname
- log.cidnumber = acidnumber
-
- return
-
- loadLogEntry: procedure expose log.
- if arg() ~= 2 then do
- rc = "loadLogEntry: bad args"
- signal error
- end
- parse arg mailbox, handle
-
- drop log.
- log. = ''
-
- if ~exists(mailboxDir(mailbox)) then do
- call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
- return
- end
-
- opened = open(handle, logFile(mailbox, handle), 'r')
- if opened then do
- call showDebugger('Loading entry' logFile(mailbox, handle))
- do while ~eof(handle)
- line = readln(handle)
- parse upper var line variable '=' value
- log.variable = value
- end
- call close(handle)
- end; else call showDebugger('Could not load' logFile(mailbox, handle))
- return
-
- /* pass a handle here */
- saveLogEntry: procedure expose log.
- if arg() ~= 2 then do
- rc = "saveLogEntry: bad args"
- signal error
- end
- parse arg mailbox, handle
-
- if ~exists(mailboxDir(mailbox)) then do
- call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
- return
- end
-
- opened = open(handle, logFile(mailbox, handle), 'w')
-
- if opened then do
- call showDebugger('Saving entry' logFile(mailbox, handle))
- call writeln(handle, 'TYPE=' || log.type)
- call writeln(handle, 'TIME=' || log.time)
- call writeln(handle, 'LENGTH=' || log.length)
-
- call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
-
- call writeln(handle, 'CIDNAME=' || log.cidname)
- call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
-
- call writeln(handle, 'COMMENT=' || log.comment)
-
- call writeln(handle, 'FILENAME=' || log.filename)
- call writeln(handle, 'ALTFILENAME=' || log.altfilename)
-
- call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
- call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
- call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
-
- call writeln(handle, 'RETURNRETRY=' || log.returnretry)
- call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
-
- call close(handle)
- address rexx 'broadcast' 'addtomailbox' mailbox handle
- end; else call showDebugger('Could not save' logFile(mailbox, handle))
-
- return
-
- /* pass a handle here */
- updateLogEntry: procedure expose log.
- if arg() ~= 2 then do
- rc = "updateLogEntry: bad args"
- signal error
- end
- parse arg mailbox, handle
-
- if ~exists(mailboxDir(mailbox)) then do
- call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
- return
- end
-
- if ~exists(logFile(mailbox, handle)) then do
- call showDebugger('Unable to update non-existent' logFile(mailbox, handle))
- return
- end
- opened = open(handle, logFile(mailbox, handle), 'w')
-
- if opened then do
- call showDebugger('Updating entry' logFile(mailbox, handle))
- call writeln(handle, 'TYPE=' || log.type)
- call writeln(handle, 'TIME=' || log.time)
- call writeln(handle, 'LENGTH=' || log.length)
-
- call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
-
- call writeln(handle, 'CIDNAME=' || log.cidname)
- call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
-
- call writeln(handle, 'COMMENT=' || log.comment)
-
- call writeln(handle, 'FILENAME=' || log.filename)
- call writeln(handle, 'ALTFILENAME=' || log.altfilename)
-
- call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
- call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
- call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
-
- call writeln(handle, 'RETURNRETRY=' || log.returnretry)
- call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
-
- call close(handle)
- address rexx 'broadcast' 'refreshmailboxentry' mailbox handle
- end; else call showDebugger('Could not update' logFile(mailbox, handle))
-
- return
-
-
-
- showDebugger: procedure
- if arg() ~= 1 then do
- say "showDebugger: ERROR"
- exit 20
- end
-
- parse arg debuggerInfo
-
- firstLine = sourceline(1)
- parse var firstLine '/*' 'TITLE:' title '*/'
- if showlist('p', 'AVMLOGGER') then
- address 'AVMLOGGER' 'add' title ':' debuggerInfo
- else
- say title ':' debuggerInfo
-
- return
-
- /*-----------------------------------------------------------------------*/
- /* signal processing */
-
- arexxerror:
- error:
- call showDebugger("Error" rc "at line" sigl)
- exit 20
-
- break_c:
- halt:
- call showDebugger("Halt/Break_C at line" sigl)
- exit 20
-
- novalue:
- call showDebugger("No value at line" sigl)
- exit 20
-
- syntax:
- call showDebugger("Syntax error" rc "at line" sigl)
- exit 20
-
- exit
-
- /* this requires logfunctions.avm */
-
- loadMailbox: procedure expose mailbox.
- if arg() ~= 1 then do
- rc = "loadMailbox: bad args"
- signal error
- end
-
- mailbox. = ''
- parse arg mailbox
-
- handle = 'mailboxconfig'
- opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'r')
- if opened then do
- do while ~eof(handle)
- line = readln(handle)
- parse upper var line variable '=' value
- mailbox.variable = value
- end
- call close(handle)
- end
- return
-
- /* pass a handle here */
- saveMailbox: procedure expose mailbox.
- if arg() ~= 1 then do
- rc = "saveMailbox: bad args"
- signal error
- end
- parse arg mailbox
-
- handle = 'mailboxconfig'
- opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'w')
-
- if opened then do
- call writeln(handle, 'PASSWORD=' || mailbox.password)
-
- call writeln(handle, 'AUTOFAXFORWARDB=' || mailbox.autofaxforwardb)
- call writeln(handle, 'AUTOFAXFORWARD=' || mailbox.autofaxforward)
- call writeln(handle, 'AUTOFAXFORWARDSCRIPT=' || mailbox.autofaxforwardscript)
-
- call writeln(handle, 'AUTOFORWARDB=' || mailbox.autoforwardb)
- call writeln(handle, 'AUTOFORWARDONDEMAND=' || mailbox.autoforwardondemand)
- call writeln(handle, 'AUTOFORWARD=' || mailbox.autoforward)
- call writeln(handle, 'AUTOFORWARDSCRIPT=' || mailbox.autoforwardscript)
-
- call writeln(handle, 'AUTOPAGEB=' || mailbox.autopageb)
- call writeln(handle, 'AUTOPAGEONDEMAND=' || mailbox.autopageondemand)
- call writeln(handle, 'AUTOPAGE=' || mailbox.autopage)
- call writeln(handle, 'AUTOPAGESCRIPT=' || mailbox.autopagescript)
-
- call writeln(handle, 'AUTOALERTB=' || mailbox.autoalertb)
- call writeln(handle, 'AUTOALERTONDEMAND=' || mailbox.autoalertondemand)
- call writeln(handle, 'AUTOALERTSCRIPT=' || mailbox.autoalertscript)
-
- call close(handle)
- end
-
- return
-
- stdabort:
- exit
-
- stdbusy:
- exit
-
- stderror:
- exit
-
- stdtimedout:
- exit
-
- stdfaxinstruct:
- 'playvoice' 'avm:voices/FaxStarting'
- action = rc
- select
- when action = 0 then nop
- when action = 1 then do; call checkifabort; end
- when action = 4 then nop
- when action = 5 then nop
- when action = 8 then signal stdbusy
- when action = 12 then signal stdabort
- when action = 14 then nop
- when action = 16 then nop
- otherwise signal arexxerror
- end
-
- stdfax:
- faxscript = getclip(address() || 'FAXSCRIPT')
- if faxscript = '' then faxscript = 'handlefax'
- if symbol('mailbox') = 'VAR' then address rexx faxscript address() mailbox
- else address rexx faxscript address() 'anonymous'
- exit
-
- stddatainstruct:
- 'playvoice' 'avm:voices/DataStarting'
- action = rc
- select
- when action = 0 then nop
- when action = 1 then do; call checkifabort; end
- when action = 4 then nop
- when action = 5 then nop
- when action = 8 then signal stdbusy
- when action = 12 then signal stdabort
- when action = 14 then nop
- when action = 16 then nop
- otherwise signal arexxerror
- end
-
- stddata:
- datascript = getclip(address() || 'DATASCRIPT')
- if datascript = '' then datascript = 'handledata'
- if symbol('mailbox') = 'VAR' then address rexx datascript address() mailbox
- else address rexx datascript address()
- exit
-
- checkifabort:
- 'readnkeys' '1' '3'
- action = rc
- if action = 0 then value = result
- select
- when action = 0 then do; if value = '*' then signal stdabort; end
- when action = 4 then nop
- when action = 5 then nop
- when action = 8 then signal stdbusy
- when action = 10 then nop
- when action = 12 then signal stdabort
- when action = 14 then signal stderror
- when action = 16 then signal stderror
- otherwise signal arexxerror
- end
- return
-
-
-